package com.piz.web.product;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.piz.model.common.FileUpload;

@Component("uploadValidator")
public class FileUploadValidator implements Validator{
	@Override
	public boolean supports(Class<?> clazz){
		return FileUpload.class.isAssignableFrom(clazz);
	 }	
	@Override
	public void validate(Object target, Errors errors){
	  FileUpload fileUpload = (FileUpload)target;
	  if(fileUpload.getFile().getSize()==0){
		   errors.rejectValue("file", "error.empty.file", "Please Select File.");
		}
	  if(fileUpload.getFile().getSize() > 10000){
		   errors.rejectValue("file", "error.empty.file", "File size more than 10000 bytes ");
		}
	}
}
